<template>
<div class="set-member">
    <query-box :queryForm="queryForm" @search="handleSearch" @reset="handleReset"></query-box>
    <table-list :tableData="tableData" @flash="handleSearch" @add="handleAdd"></table-list>
    <add-dialog :addForm="addForm" @save="handleSave"></add-dialog>
</div>
</template>

<script>
import {
    mapActions
} from 'vuex'
import AddDialog from './AddDialog'
import TableList from './TableList'
import QueryBox from './QueryBox'
export default {
    name: 'SetMember',
    components: {
        AddDialog,
        QueryBox,
        TableList
    },
    data () {
        return {
            tableData: {
                total: 0,
                pageSize: 10,
                currentPage: 1,
                list: [{
                    name: '章三1章三1章三三1',
                    date: '2018-01-01 - 2018-01-31',
                    address: '浙江省杭州市西湖区文三西路'
                },
                {
                    name: '章三2',
                    date: '2018-01-01 - 2018-01-31',
                    address: '浙江省杭州市西湖区文三西路'
                },
                {
                    name: '章三3章章三3章三3',
                    date: '2018-01-01 - 2018-01-31',
                    address: '浙江省杭州市西湖区文三西路'
                },
                {
                    name: '章三4章三4章三4章三4章三4',
                    date: '2018-01-01 - 2018-01-31',
                    address: '浙江省杭州市西湖区文三西路'
                },
                {
                    name: '章三5',
                    date: '2018-01-01 - 2018-01-31',
                    address: '浙江省杭州市西湖区文三西路'
                }
                ]
            },
            addForm: {
                show: false,
                title: '创建项目',
                form: {
                    name: '',
                    code: '',
                    desc: ''
                }
            },
            queryForm: {
                name: '',
                time: []
            }
        }
    },
    created () {
        // this.init()
    },
    methods: {
        ...mapActions({
            getInitData: 'set-member/getInitData'
        }),
        handleSave () {
            console.warn('掉用保存的接口')
            this.init()
        },
        handleSearch () {
            this.tableData.currentPage = 1
            this.init()
        },
        init () {
            console.warn('初始化数据')
            const {
                name,
                listVal,
                time
            } = this.form
            const {
                pageSize,
                currentPage
            } = this.tableData
            const params = {
                searchName: name,
                typeVal: listVal,
                startTime: time[0] && this.$moment(time[0]).format('YYYY-MM-DD'),
                endTime: time[1] && this.$moment(time[1]).format('YYYY-MM-DD'),
                pageSize: pageSize,
                currentPage: currentPage
            }
            this.getInitData(params).then(res => {
                console.warn('获取数据', res)
            })
        },
        handleReset () {
            this.queryForm = {
                name: '',
                listVal: '',
                time: []
            }
        },
        handleAdd (isNew, item) {
            this.addForm.show = true
        }
    }
}
</script>

<style lang="less">
.set-member {}
</style>
